package so.sao.code.service.domain.service;

import java.util.List;

import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;

import so.sao.code.service.domain.entity.TagBatch;
import so.sao.code.service.infrastructure.enums.CodeMessage;
import so.sao.code.service.infrastructure.enums.TAG_BATCH_TYPE;
import so.sao.top.core.util.rest.RestException;

/**
 * Created by Administrator on 2017/9/12.
 */
@Service
public class TagBatchConfigDomainService {
	public Integer computeCountPerLine(TagBatch tagBatch, Integer preTagCountPerLine) {
		switch (tagBatch.getType()) {
		case NORMAL:
		case WRAP:
			return preTagCountPerLine;
		case ROLL:
			return tagBatch.getUnitCount();
		case PACKAGE:
			return tagBatch.getRatio() + 1;
		case DUPLICATE:
			return preTagCountPerLine;
		default:
			throw new RestException(HttpStatus.BAD_REQUEST, CodeMessage.BatchTypeError, tagBatch.getType());
		}
	}

	/**
	 * 前端只设置一个标签打印格式时，自动填充剩余标签打印格式
	 */
	public String defaultFieldConfig(TAG_BATCH_TYPE type, List<String> fieldsConfig) {
		switch (type) {
		case DUPLICATE:
		case NORMAL:
		case ROLL:
		case WRAP:
			return fieldsConfig.get(0);
		case PACKAGE:
			return fieldsConfig.get(1);
		default:
			throw new RestException(HttpStatus.BAD_REQUEST, CodeMessage.BatchTypeError, type);
		}
	}
}
